<script setup lang="ts">
import { useUserInfoStore } from '@/store/userInfo'

const router = useRouter()
const userInfoStore = useUserInfoStore()

function handleViewProtocol(type: '用户协议' | '隐私政策') {
  router.push({
    name: 'protocol',
    params: { type },
  })
}

function handleLogout() {
  uni.showModal({
    title: '确定要退出吗？',
    success: (result) => {
      if (result.confirm) {
        userInfoStore.setUserInfo()
        router.replaceAll('index')
      }
    },
  })
}
</script>

<template>
  <view class="px-24rpx">
    <Spacer h="40" />
    <view class="rounded-10rpx bg-white">
      <ListCell label="用户协议" @tap.stop="() => handleViewProtocol('用户协议')">
        <ListLink />
      </ListCell>
      <Divider />
      <ListCell label="隐私政策" @tap.stop="() => handleViewProtocol('隐私政策')">
        <ListLink />
      </ListCell>
      <Divider />
      <ListCell label="退出登录" @tap="handleLogout">
        <ListLink />
      </ListCell>
    </view>
  </view>
</template>

<route lang="yaml">
name: 'settings'
style:
  navigationBarTitleText: '设置'
</route>
